import {createReducer} from '../utils';
import { REG_USER_REQUEST, REG_USER_SUCCESS, REG_USER_FAILURE } from '../contants/index';


const initialState = {
    session:null,
    isRegistered: false,
    isRegistering: false,
    statusText: null
};
export default createReducer(initialState, {
    [REG_USER_REQUEST]: (state, payload) => {
        return Object.assign({}, state, {
            'isRegistering': true,
            'statusText': null
        });
    },
    [REG_USER_SUCCESS]: (state, payload) => {
        console.log(payload);
        return Object.assign({}, state, {
            'isRegistering': false,
            'isRegistered': true,
            'session': payload.session,
            'statusText': 'You have been successfully registered .'
        });

    },
    [REG_USER_FAILURE]: (state, payload) => {
        return Object.assign({}, state, {
            'isRegistering': false,
            'isRegistered': false,
            'session': null,
            'statusText': `Authentication Error: ${payload.errCode} ${payload.errContent}`
        });
    }
});